import javax.swing.plaf.TableHeaderUI;

class MyThread extends Thread {
    @Override
    public void run() {
        while(true) {
            System.out.println("我的线程启动");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }

    }
}
class MyRunnable implements Runnable {
    @Override
    public void run() {
        System.out.println("我的任务！！");
    }

}
public class demo1 {
    public static void main1(String[] args) throws InterruptedException {
        Thread t = new MyThread();
        t.start();
        while(true) {
            System.out.println("主线程启动");
            Thread.sleep(1000);
        }
    }

    public static void main2(String[] args) throws InterruptedException {
        Thread t1 = new Thread() {
            @Override
            public void run() {
                System.out.println("线程t1启动");
            }
        };

        Thread t2 = new Thread(new Runnable() {

            @Override
            public void run() {
                System.out.println("t2");
            }
        });

        Thread t3 = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("t3线程");
            }
        }, "新线程");

        Thread t4  = new Thread(() -> {
           while(!Thread.currentThread().isInterrupted()) {
               System.out.println("线程开始工作");
               try {
                   Thread.sleep(1000);
               }catch (InterruptedException e) {
                   e.printStackTrace();
                   System.out.println("线程已经中断");

               }
           }
        });
        t4.start();
        Thread.sleep(2000);
        System.out.println("让线程终止");
        t4.interrupt();
    }

    public static int count;
    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(() -> {
           for(int i = 0; i < 50000; i++) {
               count++;
           }
        });
        Thread t2 = new Thread(() -> {
            for(int i = 0; i < 50000; i++) {
                count++;
            }
        });

        t2.start();
        t1.start();
        t1.join();
        t2.join();
        System.out.println(count);
    }
}
